using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace WPCoco.Transitions
{
    public abstract class Transition
    {
        public Transition(Scene targetScene)
        {
            this.targetScene = targetScene;
        }

        readonly Scene targetScene;

        public Scene TargetScene
        {
            get { return targetScene; }
        }

        Scene lastScene;

        public Scene LastScene
        {
            get { return lastScene; }
            private set { lastScene = value; }
        }
        
        public virtual void Initialize() 
        {
            LastScene = Coco.Shared.ActiveScene;  
        }

        public abstract void Draw(GameTime gameTime);

        public void Update(GameTime gameTime)
        {
            if (LastScene != null/* && LastScene.IsRunning*/)
                LastScene.Update(gameTime);
            if (TargetScene != null/* && TargetScene.IsRunning*/)
                TargetScene.Update(gameTime);
        }

        public event EventHandler<CustomEventArgs<Scene>> ExitScene;

        protected void RaiseExitScene(Scene scene)
        {
            if (ExitScene == null) return;
            ExitScene(this, new CustomEventArgs<Scene>(scene));
        }

        public event EventHandler<CustomEventArgs<Scene>> EnterScene;

        protected void RaiseEnterScene(Scene scene) 
        {
            if (EnterScene == null) return;
            EnterScene(this, new CustomEventArgs<Scene>(scene));
        }

        public event EventHandler EndTransition;

        protected void RaiseEndTransition()
        {
            if (EndTransition == null) return;
            EndTransition(this, EventArgs.Empty);
        }
        
    }
}
